<?php
include_once("db_connect.php");
$postdata = file_get_contents("php://input");
if (isset($postdata) && !empty($postdata)) {
    $request = json_decode($postdata);
    $plugin_name = trim($request->plugin_name);
    $plugin_detail = trim($request->plugin_detail);
    $price = trim($request->price);
    $selectedFile = trim($request->selectedFile);
    $selectedFolder = trim($request->selectedFolder);

    $sql = "INSERT INTO plugins (plugin_name, plugin_detail, price, image_url, folder_dowload) VALUES ('$plugin_name', '$plugin_detail', '$price', '$selectedFile', '$selectedFolder')";

    if ($mysqli->query($sql)) {
        $data = array('message' => 'ADD Plugin Success');
        echo json_encode($data);
    } else {
        $data = array('message' => 'ADD Plugin Falied');
        echo json_encode($data);
    }
}


	// $img_name = $_FILES['my_image']['name'];
	// $img_size = $_FILES['my_image']['size'];
	// $tmp_name = $_FILES['my_image']['tmp_name'];
	// $error = $_FILES['my_image']['error'];

	// if ($error === 0) {
	// 	if ($img_size > 125000) {
	// 		$em = "Sorry, your file is too large.";
	// 	    header("Location: index.php?error=$em");
	// 	}else {
	// 		$img_ex = pathinfo($img_name, PATHINFO_EXTENSION);
	// 		$img_ex_lc = strtolower($img_ex);

	// 		$allowed_exs = array("jpg", "jpeg", "png"); 

	// 		if (in_array($img_ex_lc, $allowed_exs)) {
	// 			$new_img_name = uniqid("IMG-", true).'.'.$img_ex_lc;
	// 			$img_upload_path = 'uploads/'.$new_img_name;
	// 			move_uploaded_file($tmp_name, $img_upload_path);

	// 			// Insert into Database
	// 			$sql = "INSERT INTO images(image_url) 
	// 			        VALUES('$new_img_name')";
	// 			mysqli_query($conn, $sql);
	// 			header("Location: view.php");
	// 		}else {
	// 			$em = "You can't upload files of this type";
	// 	        header("Location: index.php?error=$em");
	// 		}
	// 	}
	// }else {
	// 	$em = "unknown error occurred!";
	// 	header("Location: index.php?error=$em");
	// }
